package com.socket.communication;


import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @ClassName: Client
 * @Author: ZhangYue26
 * @Description: Socket实现双向通信-客户端
 * @Date: 2020-08-18
 */
public class Client {
    public static void main(String[] args) throws Exception {

        Socket socket = new Socket("localhost", 12345);
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("Fuck You".getBytes());
        outputStream.flush();
        outputStream.close();

//        InputStreamReader inputStreamReader;
//        BufferedReader bufferedReader;
//        OutputStreamWriter outputStreamWriter;
//        BufferedWriter bufferedWriter;
//        String str;
//        Scanner in = new Scanner(System.in);
//        try {
//            Socket socket = new Socket("localhost", 4444);
////     System.out.println(socket.getInetAddress());// 输出连接者的IP。
//            System.out.println("成功连接服务器");
//            while (true) {
//                outputStreamWriter = new OutputStreamWriter(socket.getOutputStream());
//                bufferedWriter = new BufferedWriter(outputStreamWriter);
//                System.out.print("回复:");
//                str = in.nextLine();
//                bufferedWriter.write(str + "\n");
//                bufferedWriter.flush();
//                inputStreamReader = new InputStreamReader(socket.getInputStream());
//                bufferedReader = new BufferedReader(inputStreamReader);
//                System.out.println(socket.getInetAddress() + ":" + bufferedReader.readLine());
//            }
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
    }

}
